package com.bird.component.lang.util.paramcheck

import com.bird.component.lang.util.log
import com.bird.component.lang.util.paramcheck.customize.CustomizeTrait
import com.bird.component.lang.util.paramcheck.inter.ICheckModel
import com.bird.component.lang.util.paramcheck.notempty.NotEmptyTrait


class ParameterCheckBuilder : NotEmptyTrait, CustomizeTrait {
    /**
     * 最终方法，进行检验
     */
    internal fun check(): String {
        val checkNode = ParamCheckUtil.getCheckNode() ?: return "参数校验失败"
        val checkModelMap: Map<String, ICheckModel> = checkNode.modelMap ?: return ""
        val sb = StringBuilder()
        checkModelMap.values
            .forEach { sb.append(it.check()) }
        if (sb.isBlank()) {
            log.info("参数校验通过！")
            return ""
        }
        val result = sb.toString().trim { it <= ' ' }
        log.info("参数校验工具结果为：{}{}", System.lineSeparator(), result)
        return result
    }

}